// Package jsonclient 实现JSON rpc客户端请求功能
package jsonclient

import (
	"net/rpc"
	"net/rpc/jsonrpc"
)

// JSONClient a object of jsonclient
type JSONClient struct {
	url       string
	tlsVerify bool
	client    *rpc.Client
}

// NewJSONClient produce a json object
func NewJSONClient(url string) (*JSONClient, error) {
	return New(url, false)
}

// New produce a jsonclient by perfix and url
func New(url string, tlsVerify bool) (*JSONClient, error) {
	client, err := jsonrpc.Dial("tcp", url)
	if err != nil {
		return nil, err
	}
	return &JSONClient{
		url:       url,
		tlsVerify: tlsVerify,
		client:    client,
	}, nil
}
